package Demo;

import java.util.Arrays;
import java.util.Comparator;

public class compara {
    public static void main(String[] args) {
        compmember[] c = new compmember[]{
                new compmember("saxonmo", 18),
                new compmember("saxonmo", 12),
                new compmember("saxonmo", 188)
        };
        Arrays.sort(c,new compimpl());
        System.out.println(Arrays.toString(c));
    }
}

class compmember  {
    private String name;
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public compmember(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return this.age + "\t" + this.name;
    }
}
class compimpl implements Comparator <compmember>{
    @Override
    public int compare(compmember c1, compmember c2) {
        return c1.getAge()-c2.getAge();
    }
}
